package javachongkao.春面向对象1;
import java.util.Arrays;
import java.util.Scanner;
//7-5（选做） jmu-枚举WeekDay(补全代码)
//本题要求编写一个枚举类WeekDay，包含周一至周日7个常量。7个常量的名字为对应的英文单词大写，常量的顺序则可观察样例获得。
//本题还要求编写将从控制台输入的字符串转化为WeekDay类型变量，然后使用swith根据该变量执行相应代码。
//最后，本题要求输出统计结果，并得到WeekDay的常量数组，然后对其进行排序并输出。以下为代码框架，请在相应位置补全代码：
//import java.util.Arrays;
//import java.util.Scanner;
/// /这里编写泛型类WeekDay的定义
//public class Main {
//    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        //这里包含一些用于统计的初始化代码
//        try {
//            while(sc.hasNext()) {
//                String weekDayStr = sc.next();
//                //这里编写将weekDayStr转化为WeekDay类型变量x的代码
//                //这里编写使用switch根据x类型输出对应信息并统计的代码
//                }
//            }
//        } catch (Exception e) {
//            System.out.println("输入错误");
//
//        }
//        //这里输出统计信息
//        //这里编写获得WeekDay常量数组并将其转化为String数组a的代码
//        //这里编写将a数组排序并打印出来的代码
//
//        sc.close();
//    }
//}
//输入格式:
//输入一些字符串，代表字符常量x
//输出格式:
//当输入的是工作日，输出：x是工作日, 序号为y；当输入的是休息日，输出：x是工作日, 序号为y
//统计结果
//按顺序排序的常量数组字符串表达形式
enum WeekDay {
    MONDAY(1, true),
    TUESDAY(2, true),
    WEDNESDAY(3, true),
    THURSDAY(4, true),
    FRIDAY(5, true),
    SATURDAY(6, false),
    SUNDAY(0, false);

    private final int order;
    private final boolean isWorkDay;

    WeekDay(int order, boolean isWorkDay) {
        this.order = order;
        this.isWorkDay = isWorkDay;
    }

    public int getOrder() {
        return order;
    }

    public boolean isWorkDay() {
        return isWorkDay;
    }

    public static WeekDay fromString(String str) {
        try {
            return valueOf(str.toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("输入错误");
        }
    }
}

public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int workDayCount = 0;
        int restDayCount = 0;

        try {
            while(sc.hasNext()) {
                String weekDayStr = sc.next();
                WeekDay x = WeekDay.fromString(weekDayStr);

                switch(x) {
                    case MONDAY:
                    case TUESDAY:
                    case WEDNESDAY:
                    case THURSDAY:
                    case FRIDAY:
                        System.out.println(x + "是工作日, 序号为" + x.getOrder());
                        workDayCount++;
                        break;
                    case SATURDAY:
                    case SUNDAY:
                        System.out.println(x + "是休息日, 序号为" + x.getOrder());
                        restDayCount++;
                        break;
                }
            }
        } catch (Exception e) {
            System.out.println("输入错误");
        }

        System.out.println("工作日共" + workDayCount + "天");
        System.out.println("休息日共" + restDayCount + "天");

        WeekDay[] days = WeekDay.values();
        String[] a = new String[days.length];
        for (int i = 0; i < days.length; i++) {
            a[i] = days[i].toString();
        }
        Arrays.sort(a);
        System.out.println(Arrays.toString(a));

        sc.close();
    }
}
